package com.example.lbstest.controller;


import java.text.SimpleDateFormat;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.example.lbstest.impl.UserMapperServiceImpl;
import com.example.lbstest.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserMapperServiceImpl service;
    private String url = "url";
    private String path = "path";

    @RequestMapping("/login")
    @ResponseBody
    public User login(HttpServletRequest request, HttpServletResponse response,
                      HttpSession session, Model model) {

        String loginname = request.getParameter("loginname");
        String password = request.getParameter("password");
        User user = service.login(loginname, password);
        System.out.println(user);
        if (user != null) {
            session.setAttribute("user", user);
        }
        return user;
    }


    public long getUId() {
        long time = System.currentTimeMillis();
        String s = String.valueOf(time);
        s=s.substring(3,13);
        long id = Long.valueOf(s);
        System.out.println(s.length());
        return id;
    }


    public String getDate() {
        Date dNow = new Date( );
        SimpleDateFormat ft =
                new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
        return ft.format(dNow);

    }

}


